package com.xhd.util;

import com.xhd.exception.DatabaseException;
import com.xhd.db.DBCenter;
import com.xhd.db.DataCentre;
import java.util.Hashtable;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;

public class DataFormat {
	public static double doubleTrim(double paramDouble, int paramInt) {
		if ((paramInt <= 0) || (paramInt > 15))
			return paramDouble;
		long l = (long) (paramDouble * Math.pow(10.0D, paramInt) + 0.5D);
		double d = l / Math.pow(10.0D, paramInt);
		String str1 = String.valueOf(d);
		if ((str1.indexOf(".") != -1)
				&& (str1.substring(str1.indexOf(".") + 1).length() > 15))
			str1 = str1.substring(0, str1.indexOf(".") + 15);
		int i = str1.indexOf(".");
		if (i != -1) {
			String str2 = str1.substring(i + 1);
			int j = str2.length();
			if (j > paramInt)
				str1 = str1.substring(0, i + paramInt);
			d = Double.parseDouble(str1);
		}
		return d;
	}

	public static String fillStr(String paramString1, String paramString2,
			int paramInt, boolean paramBoolean) {
		if (paramBoolean)
			for (int i = 0; i < paramInt; ++i)
				paramString1 = paramString2 + paramString1;
		else
			for (int j = 0; j < paramInt; ++j)
				paramString1 = paramString1 + paramString2;
		return paramString1;
	}

	public static int getByteCout(String paramString) {
		if ((paramString == null) || (paramString.equals("")))
			return 0;
		byte[] arrayOfByte = paramString.getBytes();
		if (arrayOfByte != null)
			return arrayOfByte.length;
		return 0;
	}

	public static String getClassName(String paramString) {
		if (paramString != null) {
			int i = paramString.lastIndexOf(46);
			if (i >= 0)
				paramString = paramString
						.substring(i + 1, paramString.length());
			return paramString;
		}
		return "";
	}

	public static String getReplDBFieldExp(String paramString1,
			String paramString2, String paramString3, DBCenter paramDataCentre) {
		String str = paramString1;
		switch (paramDataCentre.getDBType()) {
		case 2:
			str = " substring(" + paramString1 + ",0,patindex('%"
					+ paramString2 + "%'," + paramString1 + "))+'"
					+ paramString3 + "'+substring(" + paramString1
					+ ",patindex('%" + paramString2 + "%'," + paramString1
					+ ")+len('" + paramString2 + "'),len(" + paramString1
					+ ")) ";
		case 1:
		}
		return str;
	}

	public static int getSplitCount(String paramString1, String paramString2) {
		if ((paramString1 == null) || (paramString1.length() < 1))
			return 0;
		StringTokenizer localStringTokenizer = new StringTokenizer(
				paramString1, paramString2);
		return localStringTokenizer.countTokens();
	}

	public static String getSubString(String paramString, int paramInt) {
		if ((paramString == null) || (paramString.equals("")))
			return paramString;
		String str1 = "";
		String str2 = "";
		int i = 0;
		for (int j = 0; (j < paramInt) && (i < paramString.length()); ++j) {
			char c = paramString.charAt(i);
			str2 = String.valueOf(c);
			if ((str2.getBytes().length > 1) && (++j == paramInt))
				break;
			str1 = str1 + str2;
			++i;
		}
		return str1;
	}

	public static String parse(String paramString, String[] paramArrayOfString)
			throws Exception {
		if ((paramString == null) || (paramString.length() < 1))
			return null;
		if (paramArrayOfString.length < 1)
			return paramString;
		String str = "";
		label215: return str;
		try {
			int i = paramString.length();
			int j = paramArrayOfString.length;
			int k = 0;
			int l = 0;
			int i1 = 0;
			while (k <= i) {
				l = paramString.indexOf("{", k);
				i1 = paramString.indexOf("}", k);
				if (l > 0) {
					int i2 = Integer.parseInt(paramString.substring(l + 1, i1));
					if ((j > i2) && (paramArrayOfString[i2] != null))
						str = str + paramString.substring(k, l)
								+ paramArrayOfString[i2];
					else
						str = str + paramString.substring(k, i1 + 1);
					k = i1 + 1;
				} else {
					str = str + paramString.substring(k, i);
					break label215;
				}
			}
		} catch (Exception localException) {
			localException.printStackTrace();
		}

	}

	public static String replace(String paramString1, String paramString2,
			String paramString3) {
		if ((paramString1 == null) || (paramString2 == null)
				|| (paramString3 == null))
			return paramString1;
		String str = "";
		int i = paramString1.indexOf(paramString2);
		if (i == -1)
			return paramString1;
		while (i != -1) {
			str = str + paramString1.substring(0, i) + paramString3;
			paramString1 = paramString1.substring(i + paramString2.length());
			i = paramString1.indexOf(paramString2);
		}
		str = str + paramString1;
		return str;
	}

	public static String replaceIgnoreCase(String paramString1,
			String paramString2, String paramString3) {
		String str1 = paramString2.toLowerCase();
		String str2 = "";
		String str3 = paramString1.toLowerCase();
		for (int i = str3.indexOf(str1); i != -1; i = str3.indexOf(str1)) {
			str2 = str2 + paramString1.substring(0, i) + paramString3;
			str3 = str3.substring(i + paramString2.length());
			paramString1 = paramString1.substring(i + paramString2.length());
		}
		str2 = str2 + paramString1;
		return str2;
	}

	public static Vector splitCall(String paramString, char paramChar,
			boolean paramBoolean) throws DatabaseException {
		if (paramString == null)
			return null;
		String str1 = paramString.trim();
		int i = str1.length();
		if (i < 1)
			return null;
		Vector localVector = new Vector();
		String str2 = null;
		int j = 0;
		int k = str1.indexOf(40);
		if (k > 0) {
			if (str1.charAt(i - 1) != ')')
				throw new DatabaseException(30078, paramString);
			j = 1;
			str2 = str1.substring(0, k).trim();
			str1 = str1.substring(k + 1, i - 1);
		} else {
			if (str1.charAt(i - 1) == ')')
				throw new DatabaseException(30078, paramString);
			str2 = str1;
		}
		localVector.add(str2);
		if (j != 0) {
			i = str1.length();
			int l = 0;
			String str3 = "";
			for (k = 0; k < i; ++k) {
				char c = str1.charAt(k);
				if (c == paramChar) {
					l = (l != 0) ? 0 : 1;
					if (paramBoolean)
						continue;
					str3 = str3 + c;
				} else if ((c == ',') && (l == 0)) {
					localVector.add(str3);
					str3 = "";
				} else {
					str3 = str3 + c;
				}
			}
			localVector.add(str3);
		}
		return localVector;
	}

	public static String[] splitString(String paramString, char paramChar) {
		return splitString(paramString, String.valueOf(paramChar));
	}

	public static String[] splitString(String paramString1, String paramString2) {
		if (paramString1 == null)
			paramString1 = "";
		StringTokenizer localStringTokenizer = new StringTokenizer(
				paramString1, paramString2);
		String[] arrayOfString = new String[localStringTokenizer.countTokens()];
		if (arrayOfString.length > 0) {
			int i = 0;
			while (localStringTokenizer.hasMoreTokens())
				arrayOfString[(i++)] = ((String) localStringTokenizer
						.nextElement());
		}
		return arrayOfString;
	}

	public static String[] splitString(String paramString1,
			String paramString2, boolean paramBoolean) {
		if (paramString1 == null)
			return null;
		int i;
		if (paramBoolean) {
			StringTokenizer localStringTokenizer = new StringTokenizer(
					paramString1, paramString2, true);
			Vector localObject1 = new Vector();
			i = 0;
			Object localObject2;
			while (localStringTokenizer.hasMoreTokens()) {
				localObject2 = (String) localStringTokenizer.nextElement();
				if (((String) localObject2).equals(paramString2)) {
					if (i == 0)
						((Vector) localObject1).add("");
					i = 0;
				} else {
					i = 1;
					((Vector) localObject1).add(localObject2);
				}
			}
			if (i == 0)
				((Vector) localObject1).add("");
			if (((Vector) localObject1).size() > 0) {
				localObject2 = new String[((Vector) localObject1).size()];
				int j = 0;
				
				while (true) {
					localObject2[j] = ((String) ((Vector) localObject1).get(j));
					++j;
					if (j >= ((Vector) localObject1).size())
						 return (String[]) localObject2;
				}
			}
			return null;
		}
		StringTokenizer localStringTokenizer = new StringTokenizer(
				paramString1, paramString2);
		Object localObject1 = new String[localStringTokenizer.countTokens()];
		if (localObject1.length > 0) {
			i = 0;
			while (localStringTokenizer.hasMoreTokens())
				localObject1[(i++)] = ((String) localStringTokenizer
						.nextElement());
		}
		return ((String) (String) localObject1);
	}

	public static String[] splitString(String paramString, boolean paramBoolean) {
		if (paramString == null)
			return null;
		String str = null;
		if (paramString.indexOf(44) >= 0)
			str = ",";
		else if (paramString.indexOf(59) >= 0)
			str = ";";
		if (str == null) {
			String[] arrayOfString = (String[]) null;
			if ((paramString != null) && (paramString.length() > 0)) {
				arrayOfString = new String[1];
				arrayOfString[0] = paramString;
			} else {
				arrayOfString = new String[0];
			}
			return arrayOfString;
		}
		return splitString(paramString, str, paramBoolean);
	}

	public static int[] toIntArray(String paramString) {
		if (paramString == null)
			return null;
		paramString = paramString.trim();
		if (paramString.length() < 1)
			return null;
		String str = null;
		if (paramString.indexOf(44) >= 0)
			str = ",";
		else if (paramString.indexOf(59) >= 0)
			str = ";";
		if (str == null) {
			int[] arrayOfInt = new int[1];
			arrayOfInt[0] = Integer.parseInt(paramString);
			return arrayOfInt;
		}
		return toIntArray(paramString, str);
	}

	public static int[] toIntArray(String paramString1, String paramString2) {
		if (paramString1 == null)
			return null;
		paramString1 = paramString1.trim();
		if (paramString1.length() < 1)
			return null;
		StringTokenizer localStringTokenizer = new StringTokenizer(
				paramString1, paramString2);
		int[] arrayOfInt = new int[localStringTokenizer.countTokens()];
		if (arrayOfInt.length > 0) {
			int i = 0;
			while (localStringTokenizer.hasMoreTokens())
				arrayOfInt[(i++)] = Integer
						.parseInt(((String) localStringTokenizer.nextElement())
								.trim());
		}
		return arrayOfInt;
	}

	public static Vector toVector(String paramString) {
		if ((paramString == null) || (paramString.length() < 1))
			return null;
		String str = null;
		if (paramString.indexOf(44) >= 0)
			str = ",";
		else if (paramString.indexOf(59) >= 0)
			str = ";";
		if (str == null) {
			Vector localObject = new Vector(1);
			((Vector) localObject).add(paramString);
			return localObject;
		}
		Object localObject = new StringTokenizer(paramString, str);
		int i = ((StringTokenizer) localObject).countTokens();
		Vector localVector = new Vector(i);
		while (((StringTokenizer) localObject).hasMoreTokens())
			localVector.add(((StringTokenizer) localObject).nextElement());
		return ((Vector) localVector);
	}

	public static String toString(int paramInt1, int paramInt2) {
		String str = String.valueOf(paramInt1);
		if ((paramInt2 > 0) && (str.length() < paramInt2)) {
			paramInt2 -= str.length();
			for (int i = 0; i < paramInt2; ++i)
				str = "0" + str;
		}
		return str;
	}

	public static String filterIgnoreCase(String paramString1,
			String paramString2) {
		if ((paramString1 == null) || (paramString1.length() < 1)
				|| (paramString2 == null) || (paramString2.length() < 1))
			return paramString1;
		Hashtable localHashtable = splitToHashtable(paramString2.toLowerCase(),
				"");
		StringBuffer localStringBuffer = new StringBuffer(paramString1.length());
		StringTokenizer localStringTokenizer = new StringTokenizer(
				paramString1, ",");
		while (localStringTokenizer.hasMoreTokens()) {
			String str = (String) localStringTokenizer.nextElement();
			if (localHashtable.containsKey(str.toLowerCase()))
				continue;
			if (localStringBuffer.length() > 0)
				localStringBuffer.append(',');
			localStringBuffer.append(str);
		}
		return localStringBuffer.toString();
	}

	public static Hashtable splitToHashtable(String paramString,
			Object paramObject) {
		if ((paramString == null) || (paramString.length() < 1))
			return null;
		StringTokenizer localStringTokenizer = new StringTokenizer(paramString,
				",");
		Hashtable localHashtable = new Hashtable(
				localStringTokenizer.countTokens());
		while (localStringTokenizer.hasMoreTokens()) {
			Object localObject = localStringTokenizer.nextElement();
			localHashtable.put(localObject, paramObject);
		}
		return localHashtable;
	}

	public static int splitToMap(String paramString, Map paramMap,
			Object paramObject) {
		if ((paramString == null) || (paramString.length() < 1))
			return 0;
		int i = 0;
		StringTokenizer localStringTokenizer = new StringTokenizer(paramString,
				",");
		while (localStringTokenizer.hasMoreTokens()) {
			Object localObject = localStringTokenizer.nextElement();
			paramMap.put(localObject, paramObject);
			++i;
		}
		return i;
	}
}
